package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.appconfig.TokenProcessor;
import com.zhuss.bean.bo.core.login.TokenBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.AabException;
import com.zhuss.util.JsonUtil;

/**
 * 登录 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("logoutRedis")
public class LogoutRedis extends AbstractProcessor<Void, TokenBo> implements Processor<Void, TokenBo> {
	
	
	@Autowired
	private TokenProcessor tokenProcessor;
	
	
    /**
     * 校验
     */
    @Override
    public void check(TokenBo bo) throws AabException {
    }
    
    /**
     * 操作方法
     * @throws AabException 
     */
    @Override
    public Void process(TokenBo bo) throws AabException {
    	String token = bo.getToken();
    	Long userId = bo.getUserId();
    	tokenProcessor.delUserId(token, userId);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Void log(TokenBo param) throws AabException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.用户登录信息删除缓存.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(null);
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
